import { Controller, UseGuards, UsePipes } from '@nestjs/common'
import { ApiUseTags, ApiModelProperty, ApiBearerAuth } from '@nestjs/swagger'
import { IsNotEmpty, IsUrl } from 'class-validator'
import { Category } from '@lib/db/models/category.model'
import { InjectModel } from 'nestjs-typegoose'
import { Crud } from 'nestjs-mongoose-crud'
import { AuthGuard } from '@nestjs/passport'
import { ModelType } from '@typegoose/typegoose/lib/types';
import { NullStringToNull } from './nullstring-null.pipe'
import { CreateCategoryDto } from './dto/createCategory.dto'


@Crud({
  model: Category,
  routes: {
    find: {
      populate: 'parent',
    },
    create: {
      dto: CreateCategoryDto,
    },
  }
})
@Controller('categories')
@ApiUseTags('分类')
@UseGuards(AuthGuard('jwt'))
@ApiBearerAuth()
@UsePipes(new NullStringToNull(['parent']))
export class CategoriesController {
  constructor(
    @InjectModel(Category) private readonly model: ModelType<Category>
  ) { }
}
